<template>
  <div id="dynamic">
    <h2>出库审核</h2>
    <p><el-progress :text-inside="true" :stroke-width="24" text-inside="true" type="line" :format="format" :percentage="max" status="success"></el-progress></p>
    <!-- 查询条件 -->
    <el-form :inline="true" :model="info" class="demo-form-inline">
      <el-form-item label="请选择仓库id:">
        <el-input v-model="info.search_payId" placeholder="出库单id"></el-input>
      </el-form-item>
      <el-form-item label="请选择入库人:">
        <el-input v-model="info.search_payer" placeholder="出库人"></el-input>
      </el-form-item>
      <el-form-item label="请选择申请人:">
        <el-input v-model="info.search_register" placeholder="登记人"></el-input>
      </el-form-item>
      <el-form-item label="请输入审核时间" required>
        <el-col :span="11">
          <el-form-item prop="date1">

            <el-date-picker type="datetime" v-model="info.search_checkTime1" placeholder="选择日期"
                            value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col class="line" :span="2">-</el-col>
        <el-col :span="11">
          <el-form-item prop="date2">
            <el-date-picker type="datetime" v-model="info.search_checkTime2" placeholder="选择日期"
                            value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button type="success" @click="search" round>查询按钮</el-button>
<!--        <el-button type="success" @click="showById3()" round>添加</el-button>-->
      </el-form-item>
    </el-form>
    <!--出库查询-->
    <el-table :data="arrList" style="width: 100%">
      <el-table-column prop="payId" label="出库单id" width="150">
      </el-table-column>
      <el-table-column prop="payOrderNumber" label="出库单编号" width="150">
      </el-table-column>
      <el-table-column prop="stockId" label="仓库id" width="150">
      </el-table-column>
      <el-table-column prop="payer" label="出库人" width="150">
      </el-table-column>
      <el-table-column prop="reason" label="入库理由" width="150">
      </el-table-column>
      <el-table-column prop="totalAmount" label="总数量" width="150">
      </el-table-column>
      <el-table-column prop="totalPrice" label="总金额" width="150">
      </el-table-column>
      <el-table-column prop="orderList" label="关联订单" width="150">
      </el-table-column>
      <el-table-column prop="register" label="登记人" width="150">
      </el-table-column>
      <el-table-column prop="registerTime" label="登记时间" width="150">
      </el-table-column>
      <el-table-column prop="checker" label="审核人" width="150">
      </el-table-column>
      <el-table-column prop="checkTag" label="审核状态" width="150">
        <template slot-scope="scope">
          {{ scope.row.checkTag == "S001-3" ? "审核通过" : (scope.row.checkTag == "S001-2" ? "审核未通过" : "等待审核") }}
        </template>
      </el-table-column>
      <!--操作列-->
      <el-table-column label="修改" style="width: 50%">
<!--        <template slot-scope="scope">-->
<!--          <el-button size="mini" type="success" @click="showById(scope.$index, scope.row)" round>修改</el-button>-->
<!--        </template>-->
      </el-table-column>
      <el-table-column label="审核" style="width: 50%">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" @click="showById2(scope.$index, scope.row)" round>审核</el-button>
        </template>
      </el-table-column>
      <el-table-column label="删除" style="width: 50%">
<!--        <template slot-scope="scope">-->
<!--          <el-button size="mini" type="danger" @click="open(scope.$index, scope.row)" round>删除</el-button>-->
<!--        </template>-->
      </el-table-column>
    </el-table>
<!--    出库添加-->
    <el-dialog title="添加仓库" :visible.sync="dialogVisibleAdd" width="60%">
      <el-form :inline="true" :model="filebean" class="demo-form-inline">
<!--        <el-form-item label="出库单编号">-->
<!--          <el-input v-model="filebean.payOrderNumber" placeholder="出库单编号"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="仓库id">-->
<!--          <el-input v-model="filebean.stockId" placeholder="仓库id"></el-input>-->
<!--        </el-form-item>-->
        <el-form-item label="出库人">
          <el-input v-model="filebean.payer" placeholder="出库人"></el-input>
        </el-form-item>
        <el-form-item label="出库理由">
          <el-input v-model="filebean.reason" placeholder="出库理由"></el-input>
        </el-form-item>
        <el-form-item label="总件数">
          <el-input v-model="filebean.totalAmount" placeholder="总件数"></el-input>
        </el-form-item>
        <el-form-item label="总金额">
          <el-input v-model="filebean.totalPrice" placeholder="总金额"></el-input>
        </el-form-item>
        <el-form-item label="审核状态">
          <el-input v-model="filebean.checkTag" placeholder="审核状态"></el-input>
          <template slot-scope="scope">
            {{ scope.row.checkTag === "S001-3" ? "审核通过" : (scope.row.checkTag === "S001-2" ? "审核未通过" : "等待审核") }}
          </template>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisibleAdd = false">取 消</el-button>
          <el-button type="primary" @click="addPay">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 修改弹出对话框 -->
    <el-dialog title="动态库存修改" :visible.sync="dialogVisibleUpdate" width="60%">
      <el-form :inline="true" :model="showGather" class="demo-form-inline">
        <el-form-item label="出库单编号">
          <el-input v-model="showGather.payOrderNumber" placeholder="出库单编号"></el-input>
        </el-form-item>
        <el-form-item label="仓库id">
          <el-input v-model="showGather.stockId" placeholder="仓库id"></el-input>
        </el-form-item>
        <el-form-item label="出库人">
          <el-input v-model="showGather.payer" placeholder="出库人"></el-input>
        </el-form-item>
        <el-form-item label="出库理由">
          <el-input v-model="showGather.reason" placeholder="出库理由"></el-input>
        </el-form-item>
        <el-form-item label="总件数">
          <el-input v-model="showGather.totalAmount" placeholder="总件数"></el-input>
        </el-form-item>
        <el-form-item label="总金额">
          <el-input v-model="showGather.totalPrice" placeholder="总金额"></el-input>
        </el-form-item>
        <el-form-item label="审核状态">
          <el-input v-model="showGather.checkTag" placeholder="审核状态"></el-input>
          <template slot-scope="scope">
            {{ scope.row.checkTag === "S001-3" ? "审核通过" : (scope.row.checkTag === "S001-2" ? "审核未通过" : "等待审核") }}
          </template>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisibleUpdate = false">取 消</el-button>
          <el-button type="primary" @click="updatePay">确 定</el-button>
      </span>
    </el-dialog>
    <!--    仓库审核弹出对话框-->
    <el-dialog
        title=""
        :visible="dialogVisibleCheck"
        @close="dialogVisibleCheck = false"
    >
      <!-- 对话框内容 -->
      <h3 style="text-align: center;">仓库审核</h3>
      <el-form :model="addForm">
        <!-- 添加 id 字段 -->
        <el-form-item label="出库单id" :label-width="formLabelWidth">
          <el-input v-model="addForm.payId" placeholder="出库单id"></el-input>
        </el-form-item>
        <el-form-item label="出库单编号">
          <el-input v-model="addForm.payOrderNumber" placeholder="出库单编号"></el-input>
        </el-form-item>
        <el-form-item label="仓库id">
          <el-input v-model="addForm.stockId" placeholder="仓库id"></el-input>
        </el-form-item>
        <el-form-item label="出库人">
          <el-input v-model="addForm.payer" placeholder="出库人"></el-input>
        </el-form-item>
        <el-form-item label="出库理由">
          <el-input v-model="addForm.reason" placeholder="出库理由"></el-input>
        </el-form-item>
        <el-form-item label="总件数">
          <el-input v-model="addForm.totalAmount" placeholder="总件数"></el-input>
        </el-form-item>
        <el-form-item label="总金额">
          <el-input v-model="addForm.totalPrice" placeholder="总金额"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleCheck = false">取 消</el-button>
        <el-button type="primary" @click="checkClass">复核通过</el-button>
      </div>
    </el-dialog>
    <!---分页组件-->
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
                   :page-sizes="pageSizeList" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
                   :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      arrList: [],
      info: {
        search_payId: '',
        search_payer: '',
        search_register: '',
        search_checkTime1: '',
        search_checkTime2: '',
      },
      filebean: {
        checkTag: '',
      },
      showGather: {

      },
      addForm: {

      },
      max:0,
      regTime:"",
      // 当前页号
      currentPage: 1,
      // 当前页大小
      pageSize: 2,
      // 总记录数
      total: 0,
      // 页大小列表
      pageSizeList: [2, 5, 10, 20],
      dialogVisible: false,
      dialogVisibleAdd: false,
      dialogVisibleUpdate: false,
      dialogVisibleCheck: false,
    }
  },
  methods: {
    async list() {
      // 用es6的解构函数
      const { data: res } = await this.$http.post
      (`/community/pay/show/${this.currentPage}/${this.pageSize}`, this.info)
      this.arrList = res.rows
      this.total = res.total

      let aaa=this.total/1
      if(aaa=="Infinity"){
        this.max=0
      }else{
        this.max=aaa
      }
    },
    //修改回显
    async showById(index, row) {
      console.log('row',row)
      const { data: res } = await this.$http.post
      (`/community/pay/showById?payId=${row.payId}`)
      this.showGather = res
      this.dialogVisibleUpdate = true
    },
    //修改请求
    async updatePay(index, row) {
      console.log('row',row)
      const { data: res } = await this.$http.post
      (`/community/pay/updateById`,this.showGather)
      this.showGather = res
      this.dialogVisible = true
    },
    //add回显
    async showById3() {
      this.dialogVisibleAdd = true
    },
    async addPay() {
      const res = await this.$http.post
      (`/community/pay/add`,this.filebean)
      this.filebean = res
      if (data.status == 200) {
        console.log("添加成功")
        this.dialogVisibleAdd = false
        this.list()
      }
      alert('添加成功')
    },
    //复核回显
    async showById2(index, row) {
      console.log('row',row)
      const { data: res } = await this.$http.post
      (`/community/pay/showById?payId=${row.payId}`)
      this.addForm = res
      this.dialogVisibleCheck = true
    },
    //发送复核请求
    async checkClass() {
      try {
        const res = await this.$http.post(`/community/pay/update3/${this.currentPage}/${this.pageSize}`, this.addForm);
        console.log('addForm', this.addForm);
        if (res && res.data === true) {
          // 成功逻辑
          this.dialogVisibleCheck = false;
          // 消息提示
          this.$message('复核成功');
          // 刷新表格
          this.list();
        } else {
          // 失败逻辑
        }
      } catch (error) {
        console.error('Error in checkClass:', error);
        // 错误逻辑
      }
    },
    async open(index, row) {
      try {
        await this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        });
        const { data: res } = await this.$http.post(`/community/pay/del?payId=${row.payId}`);
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      } catch (error) {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      }
    },
    getdatatime() {
      var dt = new Date();
      var y = dt.getFullYear();
      var m = (dt.getMonth() + 1).toString().padStart(2, '0');
      var d = dt.getDate().toString().padStart(2, '0');
      var hh = dt.getHours().toString().padStart(2, '0');
      var mm = dt.getMinutes().toString().padStart(2, '0');
      var ss = dt.getSeconds().toString().padStart(2, '0');
      this.regTime = `${y}-${m}-${d} ${hh}:${mm}:${ss}`
    },
    // 页大小改变
    handleSizeChange(val) {
      this.pageSize = val
      this.list()
    },
    // 页号改变
    handleCurrentChange(val) {
      this.currentPage = val
      // 重新查询
      this.list()
    },
    // 表单查询
    search() {
      // 查询
      this.currentPage = 1
      this.list()
    },
  },
  created() {
    this.list()
  }
}
</script>

<style scoped>

</style>